package com.jiezheng.huinong.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.jiezheng.huinong.dao.PeopleManageDAOImpl;
import com.jiezheng.huinong.model.OperationStatus;
import com.jiezheng.huinong.model.PeopleInfo;
import com.jiezheng.huinong.util.JqPage;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class PeopleInfoAction extends ActionSupport {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = -5166804753938735537L;
	private JqPage pageInfo = new JqPage();
	private List<PeopleInfo> people = new ArrayList<PeopleInfo>();
	private String sord = "";
	private String sidx = "";
	
	// 查询条件
	private String cond = "";

	/**
	 * 列出所有居民信息
	 * 
	 * @return
	 */
	public String listPeopleInfo() {
		//检验当前用户的部门
		Map<String, Object> session = ActionContext.getContext().getSession();
		String deptNo = (String) session.get("deptNo");
		
		Integer total = (new PeopleManageDAOImpl()).getTotalPeopleNum(cond, deptNo);
		Integer totalPage = (Integer) (total / pageInfo.getRows())
				+ ((total % pageInfo.getRows() == 0) ? 0 : 1);
		pageInfo.setTotalPage(totalPage);
		pageInfo.setRecord(total);
		// 取得当前页
		Integer curPage = pageInfo.getPage();
		Integer startRow = (curPage - 1) * pageInfo.getRows();

		people = (new PeopleManageDAOImpl()).getPeopleInfo(cond, deptNo, startRow,
				pageInfo.getRows());
		return SUCCESS;
	}
	
	/**
	 * 未审核居民信息
	 * @return
	 */
	public String toAuditPeopleInfo() {
		//int status = OperationStatus.TO_AUDIT;
		//int status = OperationStatus.REJECTED;
		
		//检验当前用户的部门
		Map<String, Object> session = ActionContext.getContext().getSession();
		String deptNo = (String) session.get("deptNo");
		
		Integer total = (new PeopleManageDAOImpl()).getTotalToAuditPeopleNum(cond, deptNo);
		Integer totalPage = (Integer) (total / pageInfo.getRows())
				+ ((total % pageInfo.getRows() == 0) ? 0 : 1);
		pageInfo.setTotalPage(totalPage);
		pageInfo.setRecord(total);
		// 取得当前页
		Integer curPage = pageInfo.getPage();
		Integer startRow = (curPage - 1) * pageInfo.getRows();

		people = (new PeopleManageDAOImpl()).getToAuditPeopleInfo(cond, deptNo, startRow,
				pageInfo.getRows());
		return SUCCESS;
	}
	
	/**
	 * 未审核居民信息
	 * @return
	 */
	public String noAuditPeopleInfo() {
		
		//检验当前用户的部门
		Map<String, Object> session = ActionContext.getContext().getSession();
		String deptNo = (String) session.get("deptNo");
		
		int status = OperationStatus.NO_AUDIT;
		Integer total = (new PeopleManageDAOImpl()).getTotalPeopleNum(status, cond, deptNo);
		Integer totalPage = (Integer) (total / pageInfo.getRows())
				+ ((total % pageInfo.getRows() == 0) ? 0 : 1);
		pageInfo.setTotalPage(totalPage);
		pageInfo.setRecord(total);
		// 取得当前页
		Integer curPage = pageInfo.getPage();
		Integer startRow = (curPage - 1) * pageInfo.getRows();

		people = (new PeopleManageDAOImpl()).getPeopleInfo(status, cond, deptNo, startRow,
				pageInfo.getRows());
		return SUCCESS;
	}
	
	/**
	 * 已审核居民信息
	 * @return
	 */
	public String auditPeopleInfo() {
		
		//检验当前用户的部门
		Map<String, Object> session = ActionContext.getContext().getSession();
		String deptNo = (String) session.get("deptNo");
		
		int status = OperationStatus.AUDITED;
		Integer total = (new PeopleManageDAOImpl()).getTotalPeopleNum(status, cond, deptNo);
		Integer totalPage = (Integer) (total / pageInfo.getRows())
				+ ((total % pageInfo.getRows() == 0) ? 0 : 1);
		pageInfo.setTotalPage(totalPage);
		pageInfo.setRecord(total);
		// 取得当前页
		Integer curPage = pageInfo.getPage();
		Integer startRow = (curPage - 1) * pageInfo.getRows();

		people = (new PeopleManageDAOImpl()).getPeopleInfo(status, cond, deptNo, startRow,
				pageInfo.getRows());
		return SUCCESS;
	}

	public JqPage getPageInfo() {
		return pageInfo;
	}

	public void setPageInfo(JqPage pageInfo) {
		this.pageInfo = pageInfo;
	}

	public List<PeopleInfo> getPeoples() {
		return people;
	}

	public List<PeopleInfo> getPeople() {
		return people;
	}

	public void setPeople(List<PeopleInfo> people) {
		this.people = people;
	}

	public String getSord() {
		return sord;
	}

	public void setSord(String sord) {
		this.sord = sord;
	}

	public String getSidx() {
		return sidx;
	}

	public void setSidx(String sidx) {
		this.sidx = sidx;
	}

	public String getCond() {
		return cond;
	}

	public void setCond(String cond) {
		this.cond = cond;
	}

}
